<?php
namespace Admin\Model;
use Think\Model;
class CustomerModel extends Model{
	public $_validate	=	array(
		array('name','require','名称必须存在'),
		array('name','','规则标识必须唯一',self::EXISTS_VALIDATE,'unique',self::MODEL_BOTH),
		array('co_id','0','请选择所属单位',self::EXISTS_VALIDATE,'notequal',self::MODEL_BOTH)
		);

	public $_auto		=	array(
		array('createtime','time',self::MODEL_INSERT,'function'),
		array('edittime','time',self::MODEL_BOTH,'function'),
		array('uid','getId',self::MODEL_BOTH,'callback'),
		array('customer_code','getcode',self::MODEL_INSERT,'callback')
		);

	//这个函数获取session里的ID值
	public function getId(){
		return $_SESSION['uid'];
	}
	//这个函数获取code编码
	public function getcode(){
		$codeSQL="SELECT nextval('SEQ_Customer') code";
		$db=m('customer');
		$code=($db->query($codeSQL));
		$code=$code[0]['code'];
		return $code;
	}
} 